| Conditions | 1 |
| Paths | 16 |
| Total Lines | 143 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* |
||
| 38 | $(document).ready(function () { |
||
| 39 | |||
| 40 | elements.test_async_start = $('#test_async_start'); |
||
| 41 | elements.test_async_reset = $('#test_async_reset'); |
||
| 42 | elements.test_async_wait = $('#test_async_wait'); |
||
| 43 | elements.test_async_result = $('#test_async_result'); |
||
| 44 | elements.allow_linked_groups = $('#allow_linked_groups'); |
||
| 45 | elements.allow_federated_circles = $('#allow_federated_circles'); |
||
| 46 | |||
| 47 | elements.test_async_wait.hide().on('click', function () { |
||
| 48 | self.refreshResult(); |
||
|
|
|||
| 49 | }); |
||
| 50 | |||
| 51 | elements.test_async_reset.hide().on('click', function () { |
||
| 52 | $.ajax({ |
||
| 53 | method: 'DELETE', |
||
| 54 | url: OC.generateUrl('/apps/circles/admin/testAsync') |
||
| 55 | }).done(function (res) { |
||
| 56 | self.displayTestAsync(res); |
||
| 57 | }); |
||
| 58 | }); |
||
| 59 | |||
| 60 | elements.test_async_start.hide().on('click', function () { |
||
| 61 | $.ajax({ |
||
| 62 | method: 'POST', |
||
| 63 | url: OC.generateUrl('/apps/circles/admin/testAsync') |
||
| 64 | }).done(function (res) { |
||
| 65 | self.displayTestAsync(res); |
||
| 66 | }); |
||
| 67 | }); |
||
| 68 | |||
| 69 | elements.allow_linked_groups.on('change', function () { |
||
| 70 | saveChange(); |
||
| 71 | }); |
||
| 72 | |||
| 73 | elements.allow_federated_circles.on('change', function () { |
||
| 74 | saveChange(); |
||
| 75 | }); |
||
| 76 | |||
| 77 | saveChange = function () { |
||
| 78 | $.ajax({ |
||
| 79 | method: 'POST', |
||
| 80 | url: OC.generateUrl('/apps/circles/admin/settings'), |
||
| 81 | data: { |
||
| 82 | allow_linked_groups: (elements.allow_linked_groups.is( |
||
| 83 | ':checked')) ? '1' : '0', |
||
| 84 | allow_federated_circles: (elements.allow_federated_circles.is( |
||
| 85 | ':checked')) ? '1' : '0' |
||
| 86 | } |
||
| 87 | }).done(function (res) { |
||
| 88 | elements.allow_linked_groups.prop('checked', (res.allowLinkedGroups === '1')); |
||
| 89 | elements.allow_federated_circles.prop('checked', (res.allowFederatedCircles === '1')); |
||
| 90 | }); |
||
| 91 | }; |
||
| 92 | |||
| 93 | updateTestAsync = function () { |
||
| 94 | self.refreshResult(); |
||
| 95 | }; |
||
| 96 | |||
| 97 | |||
| 98 | refreshResult = function () { |
||
| 99 | $.ajax({ |
||
| 100 | method: 'GET', |
||
| 101 | url: OC.generateUrl('/apps/circles/admin/testAsync') |
||
| 102 | }).done(function (res) { |
||
| 103 | self.displayTestAsync(res); |
||
| 104 | }); |
||
| 105 | }; |
||
| 106 | |||
| 107 | displayTestAsync = function (res) { |
||
| 108 | console.log('____' + JSON.stringify(res)); |
||
| 109 | displayTestAsyncResult(res); |
||
| 110 | displayTestAsyncNewTest(res); |
||
| 111 | displayTestAsyncReset(res); |
||
| 112 | displayTestAsyncWait(res); |
||
| 113 | }; |
||
| 114 | |||
| 115 | |||
| 116 | displayTestAsyncResult = function (res) { |
||
| 117 | if (res.init !== '0') { |
||
| 118 | if (res.test.running === 0) { |
||
| 119 | elements.test_async_result.text( |
||
| 120 | 'Test is now over; final score: ' + res.test.note); |
||
| 121 | return; |
||
| 122 | } |
||
| 123 | |||
| 124 | |||
| 125 | elements.test_async_result.text( |
||
| 126 | 'Test is running. current tick: ' + res.count + '/121'); |
||
| 127 | |||
| 128 | return; |
||
| 129 | } |
||
| 130 | |||
| 131 | elements.test_async_result.text( |
||
| 132 | t('circles', 'Circles is using its own way to async heavy process.')); |
||
| 133 | }; |
||
| 134 | |||
| 135 | |||
| 136 | displayTestAsyncNewTest = function (res) { |
||
| 137 | if (res.init !== '' && res.init !== '0') { |
||
| 138 | elements.test_async_start.hide(); |
||
| 139 | return; |
||
| 140 | } |
||
| 141 | |||
| 142 | elements.test_async_start.show(); |
||
| 143 | }; |
||
| 144 | |||
| 145 | displayTestAsyncReset = function (res) { |
||
| 146 | if (res.init !== '' && res.init !== '0') { |
||
| 147 | elements.test_async_reset.show(); |
||
| 148 | return; |
||
| 149 | } |
||
| 150 | |||
| 151 | elements.test_async_reset.hide(); |
||
| 152 | }; |
||
| 153 | |||
| 154 | displayTestAsyncWait = function (res) { |
||
| 155 | if (Number(res.test.running) === 1) { |
||
| 156 | elements.test_async_reset.hide(); |
||
| 157 | elements.test_async_start.hide(); |
||
| 158 | elements.test_async_wait.show(); |
||
| 159 | return; |
||
| 160 | } |
||
| 161 | |||
| 162 | elements.test_async_wait.hide(); |
||
| 163 | }; |
||
| 164 | |||
| 165 | |||
| 166 | $.ajax({ |
||
| 167 | method: 'GET', |
||
| 168 | url: OC.generateUrl('/apps/circles/admin/settings'), |
||
| 169 | data: {} |
||
| 170 | }).done(function (res) { |
||
| 171 | elements.allow_linked_groups.prop('checked', (res.allowLinkedGroups === '1')); |
||
| 172 | elements.allow_federated_circles.prop('checked', (res.allowFederatedCircles === '1')); |
||
| 173 | }); |
||
| 174 | |||
| 175 | var timerTestAsync = setInterval(function () { |
||
| 176 | self.updateTestAsync(); |
||
| 177 | }, 4000); |
||
| 178 | |||
| 179 | |||
| 180 | }) |
||
| 181 | ; |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.